
import {
	Toast
} from 'vant';
import store from '@/store/index';
window.alipayLOT = {};
//发送消息
export const postMessage = (params) => {
	window.alipayLOT[params.action] = params;
	console.log('\x1B[40m%s\x1B[0m', '------', `alipayLOT发送[${params.action}]:`, JSON.stringify(params))
	my.postMessage({
		"action": params.action,
		"data": params.data || {}
	});

};
export default {
	//初始化
	init() {
		my.onMessage = function (e) {
			console.log('alipayLOT刚收到')
			let res = e;
			console.log('\x1B[41m%s\x1B[0m', '------', `alipayLOT收到[${res.action}]:`, JSON.stringify(res))
			if (res.success) {

				window.alipayLOT[res.action].success(res);
			} else {
				window.alipayLOT[res.action].fail && window.alipayLOT[res.action].fail(res);
				Toast({
					message: res.msg
				});
			}

		}
		console.log('alipayLOT-sdk[初始化成功]')
	},
	//刷脸核身
	faceVerify(params) {
		postMessage({
			action: 'faceVerify',
			data: params.data,
			success: (res) => {
				params.success(res);
			},
			fail: (res) => {
				params.fail(res);
			}
		})
	},
	//刷身份证
	getUserInfoByIdcard(params) {
		postMessage({
			action: 'getUserInfoByIdcard',
			success: (res) => {
				params.success(res);
			},
			fail: (res) => {
				params.fail(res);
			}
		})
	},
	//刷脸获取个人信息
	getUserInfoByFace(params) {
		postMessage({
			action: 'getUserInfoByFace',
			success: (res) => {
				params.success(res);
			},
			fail: (res) => {
				params.fail(res);
			}
		})
	},
	//获取sn号
	getSerialNumber(params) {
		postMessage({
			action: 'getSerialNumber',
			success: (res) => {
				params.success(res);
			},
			fail: (res) => {
				params.fail(res);
			}
		})
	},
	//返回首页
	backHome(params) {
		postMessage({
			action: 'backHome',
			success: (res) => {

			},
			fail: (res) => {

			}
		})
	},
	//语音
	speak(params) {
		postMessage({
			action: 'speak',
			data: params.data,
			success: (res) => {
				params.success(res);
			},
			fail: (res) => {
				params.fail(res);
			}
		})
	},
	//语音
	getConfig(params) {
		postMessage({
			action: 'getConfig',
			data: params.data,
			success: (res) => {
				params.success(res);
			},
			fail: (res) => {
				params.fail(res);
			}
		})
	},
}